home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / bin / gccmakedep < prev    next >
Text File  |  2006-04-12  |  2KB  |  127 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # makedepend which uses 'gcc -M'
  5. #
  6. # $XFree86: xc/config/util/gccmdep.cpp,v 3.10tsi Exp $
  7. #
  8. # Based on mdepend.cpp and code supplied by Hongjiu Lu <hjl@nynexst.com>
  9. #
  10.  
  11. TMP=mdep$$.tmp
  12. CC="i686-pc-linux-gnu-gcc"
  13. RM="rm -f"
  14. LN="ln -s"
  15. MV="mv -f"
  16.  
  17. ${RM} ${TMP}
  18.  
  19. trap "${RM} ${TMP}*; exit 1" 1 2 15
  20. trap "${RM} ${TMP}*; exit 0" 1 2 13
  21.  
  22. files=
  23. makefile=
  24. endmarker=
  25. magic_string='# DO NOT DELETE'
  26. append=n
  27. args=
  28.  
  29. while [ $# != 0 ]; do
  30.     if [ "$endmarker"x != x -a "$endmarker" = "$1" ]; then
  31.     endmarker=
  32.     else
  33.     case "$1" in
  34.         -D*|-I*|-U*)
  35.         args="$args '$1'"
  36.         ;;
  37.         -g*|-O*)
  38.         ;;
  39.         *)
  40.         if [ "$endmarker"x = x ]; then
  41.             case $1 in
  42. # ignore these flags
  43.             -w|-o|-cc)
  44.                 shift
  45.                 ;;
  46.             -v)
  47.                 ;;
  48.             -s)
  49.                 magic_string="$2"
  50.                 shift
  51.                 ;;
  52.             -f*)
  53.                 if [ "$1" = "-f-" ]; then
  54.                 makefile="-"
  55.                 elif [ "$1" = "-f" ]; then
  56.                 makefile="$2"
  57.                 shift
  58.                 else
  59.                 echo "$1" | sed 's/^\-f//' >${TMP}arg
  60.                 makefile="`cat ${TMP}arg`"
  61.                 rm -f ${TMP}arg
  62.                 fi
  63.                 ;;
  64.             --*)
  65.                 endmarker=`echo $1 | sed 's/^\-\-//'`
  66.                 if [ "$endmarker"x = x ]; then
  67.                 endmarker="--"
  68.                 fi
  69.                 ;;
  70.             -a)
  71.                 append=y
  72.                 ;;
  73.             -*)
  74.                 echo "Unknown option '$1' ignored" 1>&2
  75.                 ;;
  76.             *)
  77.                 files="$files $1"
  78.                 ;;
  79.             esac
  80.         fi
  81.         ;;
  82.     esac
  83.     fi
  84.     shift
  85. done
  86.  
  87. if [ x"$files" = x ]; then
  88. # Nothing to do
  89.     exit 0
  90. fi
  91.  
  92. case "$makefile" in
  93.     '')
  94.     if [ -r makefile ]; then
  95.         makefile=makefile
  96.     elif [ -r Makefile ]; then
  97.         makefile=Makefile
  98.     else
  99.         echo 'no makefile or Makefile found' 1>&2
  100.         exit 1
  101.     fi
  102.     ;;
  103. esac
  104.  
  105. if [ X"$makefile" != X- ]; then
  106.     if [ x"$append" = xn ]; then
  107.         sed -e "/^$magic_string/,\$d" < $makefile > $TMP
  108.         echo "$magic_string" >> $TMP
  109.     else
  110.         cp $makefile $TMP
  111.     fi
  112. fi
  113.  
  114. CMD="$CC -M $args $files"
  115. if [ X"$makefile" != X- ]; then
  116.     CMD="$CMD >> $TMP"
  117. fi
  118. eval $CMD
  119. if [ X"$makefile" != X- ]; then
  120.     $RM ${makefile}.bak
  121.     $MV $makefile ${makefile}.bak
  122.     $MV $TMP $makefile
  123. fi
  124.  
  125. $RM ${TMP}*
  126. exit 0
  127.